﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ServiceMessages.ResponsePOCOs;

namespace Convo
{
    public partial class ChatFriends : PhoneApplicationPage
    {
        private ConvoClient client;
        public ChatFriends()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(FriendsList_Load);
            client = new ConvoClient("http://127.0.0.1:81/Service1.svc");
        }

        void FriendsList_Load(Object sender, RoutedEventArgs e)
        {

            var request = client.friendsRequest((App.Current as App).User.ID);

            client.ExecuteAsync<List<FriendResponse>>(request, (response) =>
            {
                List<Friend> loadfriends = response.Data.Select(f => new Friend(f)).ToList();


                if (response.StatusCode == HttpStatusCode.OK && loadfriends != null)
                {
                    chatlist.ItemsSource = loadfriends;
                }
            });
        }
    }
}